import request from '@api/request';
import { HttpUrl } from '@api/httpUrl';

// 获取所有客户列表
export function getAllCustomerList() {
    return request.get<AjaxResponse['customerList']>(HttpUrl.getAllCustomerList);
}

// 获取激活/未激活客户列表
export function getCustomerList(available: boolean) {
    return request.get<AjaxResponse['customerList']>(HttpUrl.getCustomerList, { params: { available } });
}

// 排序所有客户顺序
export function reorderCustomerPriority() {
    return request.get(HttpUrl.reorderCustomerPriority);
}

// 获取单个客户信息
export function getCustomerById(customerId: string) {
    return request.get<AjaxResponse['customerList'][0]>(HttpUrl.getCustomerById, { params: { customerId } });
}

// 创建单个客户
export function createCustomer(customerForm: AjaxRequest['customerForm']) {
    return request.post(HttpUrl.createCustomer, { ...customerForm });
}

// 导入客户
export function importCustomer(data: AjaxRequest['customerForm'][]) {
    return request.post(HttpUrl.importCustomer, data);
}

// 拉取服务器保存的客户表.xlsx
export function pullCustomerList(pwd: string) {
    return request.get(HttpUrl.pullCustomerList, { params: { pwd } });
}

// 推送至服务器保存
export function pushCustomerList(data: AjaxResponse['customerList'], pwd: string) {
    return request.post(HttpUrl.pushCustomerList, { data, pwd });
}

// 更新客户
export function updateCustomer(customerData: AjaxRequest['updateCustomer']) {
    return request.put(HttpUrl.updateCustomer, { ...customerData });
}

// 删除客户
export function deleteCustomer(ids: string[]) {
    return request.put(HttpUrl.deleteCustomer, { ids });
}
